/////////////////////////////////////////////////////////////////////
//
//  MOE Framework (Meta Object Encapsulation Framework)
//
//  Original Author: Wiksy Wang, 2011
//
/////////////////////////////////////////////////////////////////////

#ifndef MOE_RAW_BYTE_VECTOR_REF_H
#define MOE_RAW_BYTE_VECTOR_REF_H

#include "RawByteVector.h"

namespace MOE
{

// A reference to a RawByteVector.
// This allows us to refer to part of the byte vector without creating a new copy.
class RawByteVectorRef
{
public:
	typedef char value_type;
	typedef size_t difference_type;

	RawByteVectorRef();
	RawByteVectorRef(const RawByteVector& ref);
	RawByteVectorRef(value_type* data, size_t length);

	operator const RawByteVector&() const
	{
		// MUST make sure the memory layout of RawByteVector and RawByteVectorRef are the same.
		return *reinterpret_cast<const RawByteVector*>(this);
	}

	operator RawByteVector&()
	{
		return *reinterpret_cast<RawByteVector*>(this);
	}

private:
	size_t _length;
	value_type* _bytes;
};

}

#endif
